﻿// /////////////////////////////////// 
//  
//  
//      WiseLink CCF2.0 
//     (c)Copyright 2001-2010 WiseLink Xiaojun (David) Chen 
//        Authored and Owned Xiaojun (David) Chen 
//        All Right Reserved
//  
// /////////////////////////////////// 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using WiseLink.RDS.Model.Common;

namespace WiseLink.RDS.Model
{
    public class DropDownListItem
    {
        public string Text { get; set; }
        public string Value { get; set; }
    }
    public class VehicleTypeRepository : RDSRepositoryBase
    {
        

        public VehicleTypeRepository(): base()
        {
        }

        public IList<DropDownListItem> GetVehicleManufacture()
        {
            var query = (from v in ccf20Ent.VehicleTypes
                         select v.Manufacture).Distinct();
            List<DropDownListItem> manufactureList = new List<DropDownListItem>();
            query.ToList().ForEach(x => manufactureList.Add(new DropDownListItem { Text = x,Value = x }));
            return manufactureList;
        }

        public IList<DropDownListItem> GetVehicleModelForManufacture(string manufacture)
        {
            var query = (from v in ccf20Ent.VehicleTypes
                         where v.Manufacture.Equals(manufacture)
                         select v.Model).Distinct();
            List<DropDownListItem> modelList = new List<DropDownListItem>();
            query.ToList().ForEach(x => modelList.Add(new DropDownListItem { Text = x, Value = x }));
            return modelList;
        }

        public IList<DropDownListItem> GetVehicleEngineTypeForManufactureModel(string input)
        {
            string[] searchCriteria = input.Split(';');
            string strManufacture = searchCriteria[0];
            string strModel = searchCriteria[1];
            var query = (from v in ccf20Ent.VehicleTypes
                         where v.Manufacture.Equals(strManufacture) && v.Model.Equals(strModel)
                         select v.EngineType).Distinct();
            List<DropDownListItem> modelList = new List<DropDownListItem>();
            query.ToList().ForEach(x => modelList.Add(new DropDownListItem { Text = x, Value = x }));
            return modelList;
        }

        public IList<DropDownListItem> GetVehicleModelYearForManufactureModelEngineType(string input)
        {
            string[] searchCriteria = input.Split(';');
            string strManufacture = searchCriteria[0];
            string strModel = searchCriteria[1];
            string strEngineType = searchCriteria[2];
            
            var query =  from v in ccf20Ent.VehicleTypes
                         where v.Manufacture.Equals(strManufacture) && v.Model.Equals(strModel) && v.EngineType.Equals(strEngineType)
                         select v;
            List<DropDownListItem> modelList = new List<DropDownListItem>();
            query.ToList().ForEach(x => modelList.Add(new DropDownListItem { Text = x.ModelYear, Value = x.VehicleTypeID.ToString() }));
            return modelList;
        }
    }

}
